package com.dtw.ditouwang.ui.mine;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.dtw.ditouwang.R;
import com.dtw.ditouwang.beans.MyMedalBean;
import com.dtw.ditouwang.models.WebApi;

import java.util.List;

public class MedalAdapter extends RecyclerView.Adapter<MedalAdapter.Holder> {
    private List<MyMedalBean.DataBeanX.DataBean> medalBeanList;

    public MedalAdapter(List<MyMedalBean.DataBeanX.DataBean> medalBeanList) {
        this.medalBeanList = medalBeanList;
    }

    @NonNull
    @Override
    public Holder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new Holder(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_medal, viewGroup, false));
    }

    @Override
    public void onBindViewHolder(@NonNull Holder holder, int i) {
        if(medalBeanList.get(i).getImg()!=null) {
            Glide.with(holder.imageView).load(WebApi.BaseUrl + medalBeanList.get(i).getImg().replace("\\", "/")).into(holder.imageView);
        }
        holder.textView.setText(medalBeanList.get(i).getMedal_name());
    }

    @Override
    public int getItemCount() {
        return medalBeanList.size();
    }

    class Holder extends RecyclerView.ViewHolder {
        ImageView imageView;
        TextView textView;

        public Holder(@NonNull View itemView) {
            super(itemView);
            imageView = itemView.findViewById(R.id.img_img);
            textView = itemView.findViewById(R.id.text_text);
        }
    }
}
